﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;

/// <summary>
/// Summary description for CommonHandle
/// </summary>
public class CommonHandle
{
    public static bool SendMail(string message, string mailFrom, string mailTo, string subject)
    {
        //  Our mail
        MailMessage ourMessage= new MailMessage();
        ourMessage.To.Add(new MailAddress(mailTo));
        ourMessage.From = new MailAddress(mailFrom);
        ourMessage.Body = message;
        ourMessage.IsBodyHtml = true;
        ourMessage.Subject = subject;

        //  SmtpClient (Class)
        //  Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).

        SmtpClient Client = new SmtpClient("smtp.live.com", 25);
        Client.EnableSsl = true;
        Client.Credentials = new System.Net.NetworkCredential("yourmail@hotmail.com", "yourpassword");

        try
        {
            Client.Send(ourMessage);    // Try to send your mail.
            return true;                // Mail sended
        }
        catch (Exception ex)
        {
            ex.ToString();
            return false;                           // Send error
        }
    }
}